import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    component: () => import('@/layout/index.vue'),
    meta: {
      title: '首页'
    },
    children: [
      {
        path: '',
        component: () => import('@/views/index/index.vue'),
        meta: {
          title: '我的主页'
        }
      },
      {
        path: 'user',
        component: () => import('@/views/user/index.vue'),
        name: 'user',
        meta: {
          title: '用户管理'
        }
      },
      {
        path: 'shop',
        component: () => import('@/views/shop/index.vue'),
        name: 'shop',
        meta: {
          title: '门店管理'
        }
      },
      {
        path: 'order',
        component: () => import('@/views/order/index.vue'),
        name: 'order',
        meta: {
          title: '订单管理'
        }
      }
    ]
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes: routes
})

router.beforeEach((to, from, next) => {
  (document as Document).title = to.meta.title as string
  next()
})

export default router